

//
//  HospitalViewController.m
//  掌上宏力
//
//  Created by admin on 17/3/9.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "HospitalViewController.h"
#import "HospitalNewsViewController.h"
#import "QJDetailViewController.h"
#import "PJDetailViewController.h"
#import "MailDetailViewController.h"
#import "OutSickerViewController.h"
#import "InSickerViewController.h"
#import "DengerousViewController.h"

#import "HPRepostViewController.h"
#import "ReportViewModel.h"

@interface HospitalViewController ()

@property (nonatomic,strong) NSArray *datasArray;
@property (nonatomic,copy) NSString *limitCode;

@end

@implementation HospitalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"宏力医院";
}

-(void)getDatasArray{
    [self getDataArray:^(GetDatas handler) {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"Hospital" ofType:@"plist"];
        _datasArray = [NSArray arrayWithContentsOfFile:path];
        handler(_datasArray);
    }];
}

//选择跳转
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:{
                HospitalNewsViewController *hpNewsV = [[HospitalNewsViewController alloc] init];
                [self pushViewControllerTo:hpNewsV];
            }
                break;
            case 1:{
                QJDetailViewController *qjV = [[QJDetailViewController alloc] init];
                [self pushViewControllerTo:qjV];
            }
                break;
            case 2:{
                PJDetailViewController *pjV = [[PJDetailViewController alloc] init];
                [self pushViewControllerTo:pjV];
            }
                break;
            case 3:{
                MailDetailViewController *mailV = [[MailDetailViewController alloc] init];
                mailV.title = @"医院邮箱";
                mailV.type = MailTypeHospital;
                [self pushViewControllerTo:mailV];
            }
                break;
            default:
                break;
        }
    }
    else if (indexPath.section == 1){
        HPRepostViewController *reportV = [[HPRepostViewController alloc] init];
        NSArray *dicArr = _datasArray[indexPath.section][@"contents"];
        NSDictionary *contentDic = dicArr[indexPath.row];
        reportV.reportName = contentDic[@"title"];
        
        if (indexPath.row <= 2) {
            reportV.type = ReportTypePersonal;
            [self pushViewControllerTo:reportV];
        }else{
            [ReportViewModel getLimitInfoSuccess:^(NSDictionary *dic) {
                _limitCode = dic[@"权限编号"];
                if (indexPath.row > 2){
                    reportV.type = ReportTypeHospital;
                    if ([_limitCode isEqualToString:@"20"]) {
                        [self pushViewControllerTo:reportV];
                    }else{
                        [SVProgressHUD showErrorWithStatus:@"无权访问"];
                    }
                }else{
                    reportV.type = ReportTypeSubject;
                    reportV.visitId = dic[@"指标编号"];
                    if ([_limitCode isEqualToString:@"19"]) {
                        [self pushViewControllerTo:reportV];
                    }else{
                        [SVProgressHUD showErrorWithStatus:@"无权访问"];
                    }
                }
            }];
        }
    }
    
    /* else if (indexPath.section == 1){
     switch (indexPath.row) {
     case 0:{
     OutSickerViewController *outSickerV = [[OutSickerViewController alloc] init];
     outSickerV.type = OutSickerTypePersonal;
     [self pushViewControllerTo:outSickerV];
     }
     break;
     case 1:{
     InSickerViewController *inSickerV = [[InSickerViewController alloc] init];
     inSickerV.type = InSickerTypePersonal;
     [self pushViewControllerTo:inSickerV];
     }
     break;
     case 2:{
     DengerousViewController *dengerV = [[DengerousViewController alloc] init];
     dengerV.type = DengerousTypePersonal;
     [self pushViewControllerTo:dengerV];
     }
     break;
     default:
     break;
     }
     }
     else if (indexPath.section == 2){
     switch (indexPath.row) {
     case 0:{
     OutSickerViewController *outSickerV = [[OutSickerViewController alloc] init];
     outSickerV.type = OutSickerTypeDepartment;
     [self pushViewControllerTo:outSickerV];
     }
     break;
     case 1:{
     InSickerViewController *inSickerV = [[InSickerViewController alloc] init];
     inSickerV.type = InSickerTypeDepartment;
     [self pushViewControllerTo:inSickerV];
     }
     break;
     case 2:{
     DengerousViewController *dengerV = [[DengerousViewController alloc] init];
     dengerV.type = DengerousTypeDepartment;
     [self pushViewControllerTo:dengerV];
     }
     break;
     default:
     break;
     }
     }*/
    
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HCommonItem *cell = [HCommonItem cellWithCollectionView:collectionView indexPath:indexPath];
    NSArray *arr = _datasArray[indexPath.section][@"contents"];
    cell.dic = arr[indexPath.row];
    
    return cell;
}

@end
